package com.j2203.controller;

import com.j2203.entity.News;
import com.j2203.service.NewsService;

import com.j2203.vo.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 查询所有
 * @Author: Captain
 * @Date: 2022/7/13 11:13
 * @version: 2019.1
 */
@RestController
@RequestMapping("/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    ResultMsg resMsg = new ResultMsg();

    @RequestMapping("/get")
    public ResultMsg selectAll(){
        List<News> all = newsService.selectAll();
        if (all !=null){
            resMsg.setStatus(200);
            resMsg.setData(all);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }

    /**
     * 单个查询
     *@Author:  Captain
     *@Date:  2022/7/13 15:22
     *@Versions:  2019.1.4
     */
    @RequestMapping("/xql")
    public ResultMsg selectOne(int gid){
        News selectOne = newsService.selectOne(gid);
        if (selectOne != null){
            resMsg.setStatus(200);
            resMsg.setData(selectOne);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
}
